import React,{useEffect} from 'react'
import {useDispatch,useSelector} from 'react-redux'
import * as api from '../../api/index'

function Shou() {
  //重新定义方法名称
  const dispatch=useDispatch();
  
  useEffect(()=>{
    //把数据发送到仓库
    dispatch(api.get_list())
  },[dispatch])

  //获取仓库中的数据
  const data=useSelector(state =>{
    return state.reducer.data;
  })
  console.log(data)
  return (
    <div>
      
      {
        data && data.map((item,index)=>{
          return <div className='list' key={index}>
              <img src={item.img} alt="" />
              <span>{item.title}</span>
          </div>
        })
      }
    </div>
  )
}

export default Shou